package com.jiaai.web.gift;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.auth.model.AccessUser;
import com.jiaai.exception.ServerException;
import com.jiaai.filter.aop.TokenIntercept;
import com.jiaai.gift.api.IGiftApi;
import com.jiaai.gift.model.BGift;
import com.jiaai.gift.model.VGiftItemVO;
import com.jiaai.util.RequestUtils;
import com.jiaai.util.RestResultGenerator;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title GiftController
 * @since 2017/10/12
 */
@RestController
@RequestMapping("/api/v1/app/gift")
public class GiftController {
    @Reference
    private IGiftApi giftApi;

    /**
     * 赠送礼物
     * @param gift
     */
    @PostMapping("/bestowed")
    @TokenIntercept(checkVisitor = true)
    public  Object bestowed(@RequestBody BGift gift)throws ServerException{
        AccessUser user = RequestUtils.getUser();
        gift.setMemgerId(user.getUserId());
        gift.setMemberIsVip(user.isVip());
        gift.setNickName(user.getNickName());
        return  RestResultGenerator.genSuccessResult(giftApi.bestowed(gift));
    }

    /**
     *
     * @return
     */
    @GetMapping("/all")
    public  Object loadGiftByAll()throws  ServerException{
       return giftApi.findByAll();
    }





}
